﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lapas.Common.Forms;
using Lapas.Common;
using WorkDAL.Users;
using Common;
using WorkDAL;

namespace Users
{
    public partial class UsersPermissionForm : EditForm
    {
        public UsersPermissionForm()
        {
            InitializeComponent();
            UIFormat.FormatGrid(mainGrid, false, true, false, false);
            UIFormat.SetGridColumnFormat(ColCaption, FormatType.NormalText);
            base.OkButton = btnOK;
            base.CloseButton = btnClose;
        }

        public List<UsersPermissionObject> userPermission = new List<UsersPermissionObject>();
        public tbUser user = new tbUser();

        private void UsersPermissionForm_Load(object sender, EventArgs e)
        {
            mainGrid.DataSource = userPermission;
            FormatDataGrid.Instance().FormatBoldGrid(mainGrid, ColMenuLevel.Name.ToString(), "1");
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                string stringPermission = ",";
                foreach (UsersPermissionObject item in userPermission)
                {
                    if (item.AllowPermission)
                        stringPermission += item.Id.ToString() + ",";
                }

                user.Permisstion = stringPermission;
                UserDataAccess.Instance().UpdatePermission(user);
                DisplayMessage.ShowNotice("Đã thực hiện xong!");
            }
            catch (Exception ex)
            {
                DisplayMessage.ShowError(ex.Message);
                return;
            }
            
        }
 
        //private void FormatGrid()
        //{
        //    int columnCount = mainGrid.ColumnCount;

        //    foreach (DataGridViewRow row in mainGrid.Rows)
        //    {
        //        if (row.Cells[ColMenuLevel.Name].Value.ToString() == "1")
        //        {
        //            for (int i = 0; i < columnCount; i++ )
        //                row.Cells[i].Style.Font = new Font(mainGrid.Font, FontStyle.Bold);
        //        }
        //    }
        //}



    }
}
